package com.jama.carouselviewexample.slice;

import com.jama.carouselviewexample.ResourceTable;
import com.jama.carouselviewexample.ability.CenteredCarouseAbility;
import com.jama.carouselviewexample.ability.ImageCarouselAbility;
import com.jama.carouselviewexample.ability.StartCarouselAbility;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.text.Font;

/**
 * MainAbilitySlice
 *
 * @since 2021-05-20
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Button tvImage;
    private Button tvCenter;
    private Button tvStart;
    private Text text;

    /**
     * intent
     *
     * @param intent intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        tvImage = (Button) findComponentById(ResourceTable.Id_tv_image);
        tvCenter = (Button) findComponentById(ResourceTable.Id_tv_centered);
        tvStart = (Button) findComponentById(ResourceTable.Id_tv_Start);
        text = (Text) findComponentById(ResourceTable.Id_tv_title);
        text.setFont(Font.DEFAULT_BOLD);
        tvImage.setClickedListener(this);
        tvCenter.setClickedListener(this);
        tvStart.setClickedListener(this);

    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     *
     * @param intent intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /**
     * component
     *
     * @param component component
     */
    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_tv_image:
                nextPage(ImageCarouselAbility.class);
                break;
            case ResourceTable.Id_tv_centered:
                nextPage(CenteredCarouseAbility.class);
                break;
            case ResourceTable.Id_tv_Start:
                nextPage(StartCarouselAbility.class);
                break;
            default:
                break;
        }
    }


    /**
     * nextPage
     *
     * @param pageName
     */
    public void nextPage(Class pageName) {
        Intent secondIntent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withDeviceId("")
                .withAbilityName(pageName.getName())
                .build();
        secondIntent.setOperation(operation);
        startAbility(secondIntent);
    }
}
